package com.jsmile.cloud.msgcenter.msg.repo;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsmile.cloud.msgcenter.api.req.ReqNotifyCreate;
import com.jsmile.cloud.msgcenter.msg.dao.MsNotifyDao;
import com.jsmile.cloud.msgcenter.msg.model.MsNotify;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2020年06月07日 11:17:04
 */
@Service
@Slf4j
@AllArgsConstructor
@Transactional(readOnly = false, rollbackFor = Exception.class)
public class MsNotifyRepository extends ServiceImpl<MsNotifyDao, MsNotify> {

    private final MsUserNotifyRepository msUserNotifyRepository;

    public Boolean create(ReqNotifyCreate reqNotifyCreate) {
        MsNotify msNotify = MsNotify.create(reqNotifyCreate);
        if (this.save(msNotify)) {
            msUserNotifyRepository.saveBatch(msNotify.getMsUserNotifies());
        }
        return Boolean.FALSE;
    }
}
